<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<c:set var="uri" value="${pageContext.request.contextPath}" />
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>学生</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/layui/css/layui.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/global.css">
            <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/icheck/minimal/red.css">
                <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/common/page/myPagination.css?t=4" />
                    
                    </head>
                    <body class="layui-layout-body" style="overflow:scroll;">
                    <style type="text/css">
                    .btnStyle{
                        margin-left:8px;
                        margin-top:8px
                    }
                    .loadingModel {
                        position: absolute;
                        top: 0;
                        left: 0;
                        background-color: rgba(9, 9, 9, 0.63);
                        width: 100%;
                        height: 100%;
                        z-index: 1000;
                    }
                    
                    
                    .loading-content {
                        width: 50%;
                        text-align: center;
                        background: #ffffff;
                        border-radius: 6px;
                        line-height: 30px;
                        z-index: 10001;
                    }
                    </style>
                    <div id="loadingDiv"></div>
                    <div id="imgModal"></div>
                    <fieldset class="layui-elem-field">
                    <legend>学生</legend>
                    <div class="layui-field-box">
                    <div class="layui-form" action="">
                    <div class="layui-form-item" style="text-align:center;">
                    
                    <div class="layui-inline" style="margin-left:100px;">
                    <label>学号</label>
                    </div>
                    <div class="layui-inline">
                    <div class="layui-input-inline" >
                    <input type="text"  style="width:250px;display:inline"  placeholder="请输入学号进行查询" id="stuNo" class="layui-input">
                    </div>
                    </div>
                    
                    <div class="layui-inline" style="margin-left:100px;">
                    <label>姓名</label>
                    </div>
                    <div class="layui-inline">
                    <div class="layui-input-inline" >
                    <input type="text"  style="width:250px;display:inline"  placeholder="请输入姓名进行查询" id="realName" class="layui-input">
                    </div>
                    </div>
                    
                    <div class="layui-inline" style="margin-left:100px;">
                    <label>所属专业</label>
                    </div>
                    <div class="layui-inline">
                    <div class="layui-input-inline" >
                    <select  id="majorId" style="height:30px;width:250px;display:inline" >
                    <option value="">全部</option>
                    <c:forEach items="${majorInfoList}" var="item">
                        <option value="${item.id}">${item.name}</option>
                            </c:forEach>
                            </select>
                            
                            </div>
                            </div>
                            <div style="margin-top:30px;"></div>
                            
                            <div class="layui-inline" style="margin-left:100px;">
                            <label>班级</label>
                            </div>
                            <div class="layui-inline">
                            <div class="layui-input-inline" >
                            <select  id="classId" style="height:30px;width:250px;display:inline" >
                            <option value="">全部</option>
                            <c:forEach items="${classInfoList}" var="item">
                                <option value="${item.id}">${item.name}</option>
                                    </c:forEach>
                                    </select>
                                    
                                    </div>
                                    </div>
                                    
                                    <div class="layui-inline" style="margin-left:100px;">
                                    <label>学期id</label>
                                    </div>
                                    <div class="layui-inline">
                                    <div class="layui-input-inline" >
                                    <select  id="termId" style="height:30px;width:250px;display:inline" >
                                    <option value="">全部</option>
                                    <c:forEach items="${termInfoList}" var="item">
                                        <option value="${item.id}">${item.name}</option>
                                            </c:forEach>
                                            </select>
                                            
                                            </div>
                                            </div>
                                            
                                            <button type="button" onclick="ajaxList(1);" style="margin-left:50px" class="layui-btn layui-btn-radius" ><i class="layui-icon layui-icon-search"></i>查询</button>
                                            
                                            </div>
                                            </div>
                                            
                                            <hr>
                                            <div class="layui-form-item">
                                            
                                            <span id="batchUpdateDiv">
                                            
                                            </span>
                                            <span class="l" id="globalBtns">
                                            <a href="${pageContext.request.contextPath}/teacher/student_info/add" class="layui-btn layui-btn-radius">新增</a>
                                                <a href="javascript:;" onclick="$('#import_data_input').click()" class="layui-btn layui-btn-normal layui-btn-radius">导入</a>
                                                <a href="${pageContext.request.contextPath}/teacher/student_info/import_data_model" class="layui-btn layui-btn-normal layui-btn-radius">下载导入导入模板</a>
                                                    <form id="import_dataForm"  style="margin:0px;display: inline" action="${pageContext.request.contextPath}/teacher/student_info/import_data" enctype="multipart/form-data" method="post">
                                                        <div style="display:none;"><input type="file" name="file" onclick="this.form.reset();" id="import_data_input" /></div>
                                                        </form>
                                                        
                                                        </span>
                                                        </div>
                                                        <hr>
                                                        <table class="layui-table">
                                                        
                                                        <thead>
                                                        <tr  style="text-align:center">
                                                        <th>学号</th>
                                                        <th>登录密码</th>
                                                        <th>姓名</th>
                                                        <th>性别</th>
                                                        <th>联系电话</th>
                                                        <th>所属专业</th>
                                                        <th>班级</th>
                                                        <th>方向</th>
                                                        <th>入学年份</th>
                                                        <th>学期id</th>
                                                        <th>创建时间</th>
                                                        <th style="width:200px;">操作</th>
                                                        
                                                        </tr>
                                                        </thead>
                                                        <tbody id="student_info_body">
                                                        
                                                        </tbody>
                                                        </table>
                                                        
                                                        <div id="student_info_bar" class="pagination" style="margin-top:20px;">
                                                        </div>
                                                        </div>
                                                        </fieldset>
                                                        
                                                        <script type="text/javascript" src="${pageContext.request.contextPath}/static/common/jquery-1.11.1.min.js"></script>
                                                            <script type="text/javascript" src="${pageContext.request.contextPath}/static/common/page/myPagination.js"></script>
                                                                <script type="text/javascript" src="${pageContext.request.contextPath}/static/common/jquery-form.js"></script>
                                                                    
                                                                    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui/layui.js"></script>
                                                                        <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layuiutil.js"></script>
                                                                            
                                                                            
                                                                            
                                                                            <script type="text/javascript" src="${pageContext.request.contextPath}/static/common/utils/listutils.js?v=4895"></script>
                                                                                <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/common/selectSearch/jquery.searchableSelect.css?d=12939" />
                                                                                    <script type="text/javascript" src="${pageContext.request.contextPath}/static/common/selectSearch/jquery.searchableSelect.js?d=124393"></script>
                                                                                        
                                                                                        
                                                                                        
                                                                                        <script type="text/javascript">
                                                                                        
                                                                                        $(function(){
                                                                                            $('#majorId').next().remove();
                                                                                            $('#majorId').searchableSelect();
                                                                                            $("#majorId").change(function(){
                                                                                                changeMajorIdVal();
                                                                                            });
                                                                                            changeMajorIdVal();
                                                                                            $("#majorId").change(function(){
                                                                                                changeMajorIdVal();
                                                                                            });
                                                                                            changeMajorIdVal();
                                                                                            $('#classId').next().remove();
                                                                                            $('#classId').searchableSelect();
                                                                                            $('#termId').next().remove();
                                                                                            $('#termId').searchableSelect();
                                                                                            $('input[id=import_data_input]').on('change',function() {
                                                                                                showLoading('${pageContext.request.contextPath}/static/common/loading.gif');
                                                                                                    $('#import_dataForm').ajaxSubmit({
                                                                                                        success: function (data) {
                                                                                                            hideLoading();
                                                                                                            alert(data.msg);
                                                                                                            ajaxList(1);
                                                                                                        }
                                                                                                    });
                                                                                                });
                                                                                                
                                                                                                ajaxList(1);
                                                                                                
                                                                                                
                                                                                            });
                                                                                            
                                                                                            function ajaxList(page) {
                                                                                                var stuNo = $("#stuNo").val();
                                                                                                var realName = $("#realName").val();
                                                                                                var majorId = $("#majorId").val();
                                                                                                var classId = $("#classId").val();
                                                                                                var termId = $("#termId").val();
                                                                                                
                                                                                                
                                                                                                showLoading('${pageContext.request.contextPath}/static/common/loading.gif');
                                                                                                    $.ajax({
                                                                                                        type : 'get',
                                                                                                        url : "${pageContext.request.contextPath}/teacher/student_info/queryList",
                                                                                                            data : {
                                                                                                                "page":page,
                                                                                                                "stuNo":stuNo,
                                                                                                                "realName":realName,
                                                                                                                "majorId":majorId,
                                                                                                                "classId":classId,
                                                                                                                "termId":termId
                                                                                                                
                                                                                                            },
                                                                                                            success : function(result) {
                                                                                                                hideLoading();
                                                                                                                var rows = result.list;//得到数据列
                                                                                                                var total = result.count;//得到数据总数
                                                                                                                lastPage=result.totalPage;
                                                                                                                totalCount=total;
                                                                                                                var html = '';
                                                                                                                for (var i = 0; i < rows.length; i++) {
                                                                                                                    html += '<tr>' ;
                                                                                                                    var stuNoVal=setNullToEmpty(rows[i].studentInfo.stuNo);
                                                                                                                    html+='<td>'+ stuNoVal+'</td>';
                                                                                                                    var passWordVal=setNullToEmpty(rows[i].studentInfo.passWord);
                                                                                                                    html+='<td>'+ passWordVal+'</td>';
                                                                                                                    var realNameVal=setNullToEmpty(rows[i].studentInfo.realName);
                                                                                                                    html+='<td>'+ realNameVal+'</td>';
                                                                                                                    var sexVal=setNullToEmpty(rows[i].sexStr);
                                                                                                                    html+='<td>'+sexVal+'</td>';
                                                                                                                    var celPhoneVal=setNullToEmpty(rows[i].studentInfo.celPhone);
                                                                                                                    html+='<td>'+ celPhoneVal+'</td>';
                                                                                                                    var majorIdVal=setNullToEmpty(rows[i].majorIdStr);
                                                                                                                    html+='<td>'+ majorIdVal+'</td>';
                                                                                                                    var classIdVal=setNullToEmpty(rows[i].classIdStr);
                                                                                                                    html+='<td>'+ classIdVal+'</td>';
                                                                                                                    var directIdVal=setNullToEmpty(rows[i].directIdStr);
                                                                                                                    html+='<td>'+ directIdVal+'</td>';
                                                                                                                    var enterYearVal=setNullToEmpty(rows[i].studentInfo.enterYear);
                                                                                                                    html+='<td>'+ enterYearVal+'</td>';
                                                                                                                    var termIdVal=setNullToEmpty(rows[i].termIdStr);
                                                                                                                    html+='<td>'+ termIdVal+'</td>';
                                                                                                                    var createTimeVal=setNullToEmpty(rows[i].studentInfo.createTime);
                                                                                                                    html+='<td>'+ createTimeVal+'</td>';
                                                                                                                    html+='<td>';
                                                                                                                    html+='<a href="${pageContext.request.contextPath}/teacher/student_info/update?id='+rows[i].studentInfo.id+'" class="layui-btn layui-btn-normal layui-btn-radius btnStyle">修改</a>';
                                                                                                                        html+='<a href="javascript:void(0)" onclick="del(this)" data-id="'+rows[i].studentInfo.id+'" class="layui-btn layui-btn-danger layui-btn-radius btnStyle">删除</a>';
                                                                                                                        html+='</td>';
                                                                                                                        html+='</tr>';
                                                                                                                    }
                                                                                                                    if (rows.length == 0) {
                                                                                                                        html += '<tr><td></td><td></td><td></td><td></td><td></td><td></td><td>无数据</td><td></td><td></td><td></td><td></td><td></td></tr>';
                                                                                                                    }
                                                                                                                    $("#student_info_body").html(html);
                                                                                                                    
                                                                                                                    
                                                                                                                    new myPagination({
                                                                                                                        id: 'student_info_bar',
                                                                                                                        curPage:page, //初始页码
                                                                                                                        pageTotal: result.totalPage, //总页数
                                                                                                                        pageAmount: 10,  //每页多少条
                                                                                                                        dataTotal: total, //总共多少条数据
                                                                                                                        pageSize: 5, //可选,分页个数
                                                                                                                        showPageTotalFlag:true, //是否显示数据统计
                                                                                                                        showSkipInputFlag:false, //是否支持跳转
                                                                                                                        getPage: function (page) {
                                                                                                                            ajaxList(page);
                                                                                                                        }
                                                                                                                    })
                                                                                                                    
                                                                                                                }
                                                                                                            });
                                                                                                        }
                                                                                                        
                                                                                                        function changeMajorIdVal(){
                                                                                                            var id = $("#majorId").val();
                                                                                                            $.ajax({
                                                                                                                async:false,
                                                                                                                type: 'post',
                                                                                                                url: '${pageContext.request.contextPath}/teacher/student_info/getClassInfoListByMajorId',
                                                                                                                    data:{
                                                                                                                        "majorId":id
                                                                                                                    },
                                                                                                                    success: function(result) {
                                                                                                                        var html='<option value="" >全部</option>';
                                                                                                                        for(var i=0;i<result.length;i++){
                                                                                                                            html+='<option value='+result[i].id+' >'+result[i].name+'</option>';
                                                                                                                        }
                                                                                                                        $("#classId").html(html);
                                                                                                                        $("#classId").next().remove();
                                                                                                                        $("#classId").searchableSelect();
                                                                                                                    }
                                                                                                                });
                                                                                                            }
                                                                                                            function changeMajorIdVal(){
                                                                                                                var id = $("#majorId").val();
                                                                                                                $.ajax({
                                                                                                                    async:false,
                                                                                                                    type: 'post',
                                                                                                                    url: '${pageContext.request.contextPath}/teacher/student_info/getMajorDirectInfoListByMajorId',
                                                                                                                        data:{
                                                                                                                            "majorId":id
                                                                                                                        },
                                                                                                                        success: function(result) {
                                                                                                                            var html='<option value="" >全部</option>';
                                                                                                                            for(var i=0;i<result.length;i++){
                                                                                                                                html+='<option value='+result[i].id+' >'+result[i].name+'</option>';
                                                                                                                            }
                                                                                                                            $("#directId").html(html);
                                                                                                                            $("#directId").next().remove();
                                                                                                                            $("#directId").searchableSelect();
                                                                                                                        }
                                                                                                                    });
                                                                                                                }
                                                                                                                function del(e){
                                                                                                                    if(window.confirm('你确定要删除该学生吗')){
                                                                                                                        var id = $(e).attr("data-id");
                                                                                                                        $.ajax({
                                                                                                                            type : 'get',
                                                                                                                            url : "${pageContext.request.contextPath}/teacher/student_info/del",
                                                                                                                                data : {
                                                                                                                                    "id":id
                                                                                                                                },
                                                                                                                                success : function(result) {
                                                                                                                                    alert(result.msg);
                                                                                                                                    if(result.code==1){
                                                                                                                                        ajaxList(1);
                                                                                                                                    }
                                                                                                                                }
                                                                                                                            });
                                                                                                                            return true;
                                                                                                                            }else{
                                                                                                                                return false;
                                                                                                                            }
                                                                                                                        }
                                                                                                                        
                                                                                                                        
                                                                                                                        function gotoPage(e){
                                                                                                                            
                                                                                                                            var url = $(e).attr("data-url");
                                                                                                                            window.location.href=url;
                                                                                                                        }
                                                                                                                        
                                                                                                                        </script>
                                                                                                                        
                                                                                                                        </body>
                                                                                                                        </html>
